package com.example.arithmeticleetcode.leetcode;

/**
 * @program: arithmetic-leetcode
 * @description:
 * @author: FangZhen
 * @create: 2020-06-18 10:35
 **/
public class Demo31 {

    public static void main(String[] args) {
        int[] prices = {8, 4, 6, 2, 3};
        int[] prices1 = {1, 2, 3, 4, 5};
        int[] prices2 = {10, 1, 1, 6};
        finalPrices(prices);
        finalPrices(prices1);
        finalPrices(prices2);
    }

    public static int[] finalPrices(int[] prices) {
        int[] arr = new int[prices.length];
        for (int i = 0, len = prices.length; i < len; i++) {
            int account = 0;
            for (int j = i + 1; j < len; j++) {
                if (prices[i] >= prices[j]) {
                    account = prices[j];
                    break;
                }
            }
            arr[i] = prices[i] - account;
            System.out.print(arr[i] + " ");
        }
        System.out.println("-----");
        return arr;
    }
}
